/**
 * 1.属性的默认值:defaultProps
 * 2.属性的json数据
 * */
import ConfigButton from './web/configButton';
import { getIsWf } from '@inbiz/utils';
import {
  createInbizSchema,
  createEmptySchema,
  createDecoratorStyleSchema,
  createComponentStyleSchema,
  createReactiveStyleSchema,
  createControllerSchema,
  createBaseSchema,
} from '@inbiz/setters';
import { ProcessButton as LocaleProcessButton } from './locale';
import { getMessage } from '@inbiz/react';
export const defaultProps = {
  // labeltext: 'processButton.labeltext',
  tips: '',
  buttonVisible: 'visible',
  webbuttonConfig: [
    {
      action: 'initiate',
      name: 'processButton.initiate',
      type: 'initiate',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
    {
      action: 'approve',
      name: 'processButton.approve',
      type: 'approve',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
    {
      action: 'returnsBack',
      name: 'processButton.returnsBack',
      type: 'returnsBack',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
    {
      action: 'cancel',
      name: 'processButton.cancel',
      type: 'cancel',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
  ],
  wapbuttonConfig: [
    {
      action: 'initiate',
      name: 'processbutton.initiate',
      type: 'initiate',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
    {
      action: 'approve',
      name: 'processButton.approve',
      type: 'approve',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
    {
      action: 'returnsBack',
      name: 'processButton.returnPrestep',
      type: 'returnsBack',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
    {
      action: 'cancel',
      name: 'processButton.cancel',
      type: 'cancel',
      // bgColor: 'var(--inbiz-color-primary)',
      bgColor: '#1989fa',
      id: '',
      taskType: 'faqishenqing',
    },
  ],
  radius: 4,
  showCCmember: true,
  showComment: true,
};

export const propsSchema = createInbizSchema({
  attribute: {
      base: {
        type: 'void',
        'x-component': 'CollapseItem',
        properties: {
          'x-display': {
            type: 'string',
            enum: ['visible', 'hidden'],
            'x-decorator': 'FormItem',
            'x-component': 'Select',
            'x-component-props': {
              defaultValue: 'visible',
            },
          },
          'x-component-props': {
            type: 'object',
            properties: {
              tips: {
                type: 'text',
                'x-decorator': 'FormItem',
                'x-component': 'MultilingualInput',
                'x-component-props': {
                  placeholder: getMessage('processButton.tipsContent'),
                },
              },
              webbuttonConfig: {
                type: 'array',
                'x-decorator': 'FormItem',
                'x-component': ConfigButton,
                'x-component-props': {
                  type: 'web',
                },
                'x-reactions': (field: any) => {
                  if (getIsWf()) {
                    field?.setDisplay(false);
                  };
                },
                platform: 'web',
              },
              wapbuttonConfig: {
                type: 'array',
                'x-decorator': 'FormItem',
                'x-component': ConfigButton,
                'x-component-props': {
                  type: 'wap',
                },
                'x-reactions': (field: any) => {
                  if (getIsWf()) {
                    field?.setDisplay(false);
                  };
                },
                platform: 'wap',
              },
              showCCmember: {
                type: 'array',
                'x-decorator': 'FormItem',
                'x-component': 'Switch',
                'x-component-props': {
                  defaultValue: true,
                },
                platform: 'web',
              },
              showComment: {
                type: 'array',
                'x-decorator': 'FormItem',
                'x-component': 'Switch',
                'x-component-props': {
                  defaultValue: true,
                },
                platform: 'web',
              },
  
            }
        },

      },
    }
  },
  
  style: {
    ...createComponentStyleSchema(),
    ...createDecoratorStyleSchema(),
    // ...createReactiveStyleSchema({
    //   radius: {
    //     type: 'string',
    //     'x-decorator': 'FormItem',
    //     'x-component': 'InputNumber',
    //     'x-component-props': {
    //       defaultValue: 4,
    //     },
    //   },
    // }),
  },
  controller: createControllerSchema({
    events: [{
      name: 'onClick',
      label: '点击'
    }, {
      name: 'onBeforeSubmit',
      label: '发起之前',
      isConfigEvent: true,
    }, {
      name: 'onAfterSubmit',
      label: '发起之后',
      isConfigEvent: true,
    }, {
      isConfigEvent: true,
      name: 'onBeforeClose',
      label: '关闭之前'
    }]
  })
});

export const defaultBehavior = {
  name: 'ProcessButton',
  selector: (node) => node.props['x-component'] === 'ProcessButton',
  extends: ['Field'],
  designerLocales: LocaleProcessButton,
  designerProps: { propsSchema },
};

export const defaultResource = {
  icon: 'ProcessButton',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'void',
        'x-decorator': 'Container',
        'x-decorator-props': {
          clickable: true,
        },
        'x-component': 'ProcessButton',
        'x-component-props': defaultProps,
      },
    },
  ],
};
